package com.henu.engineer.config

import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.web.servlet.HandlerInterceptor
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
 * @author noexcept
 * @date 2021/7/23 0:24
 */
class RequestInterceptor : HandlerInterceptor {

    val logger: Logger = LoggerFactory.getLogger(javaClass)

    /**
     * 对除登录(/login)以外的所有请求进行验证
     * 判断是否登录,只有登陆了才能执行一些请求。
     * @see WebConfig.addInterceptors
     * @see com.henu.engineer.controller.LoginController.login
     */
//    override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
//        val session = request.session
//        val isLogged = session.getAttribute("isLogged") as Boolean
//        //判断是否已登录
//        if (!isLogged)
//            return false
//
//        //如果登陆了，判断是否具有权限访问该路径
//        val uri = request.requestURI
//        val rank = (session.getAttribute("rank") as String).lowercase()
//        return uri.startsWith("/ga")
//                || uri.startsWith("/$rank")
//                || (uri.startsWith("/cl") || uri.startsWith("/pl") && rank == "cp")
//        return true
//    }
}